﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CFSystem.JXC.BasisInfo
{
    public partial class UCBaseSetting : UserControl
    {
        public delegate void UCBaseSettingAddhandler();
        public event UCBaseSettingAddhandler OnAddEvent;

        public delegate void UCBaseSettingDelhandler();
        public event UCBaseSettingDelhandler OnDelEvent;

        public delegate void UCBaseSettingUpdhandler();
        public event UCBaseSettingUpdhandler OnUpdEvent;


        public delegate void UCBaseSettingRowSelecthandler(object sender, DataGridViewCellEventArgs e);

        public event UCBaseSettingRowSelecthandler OnRowSelectedEvent;

        public UCBaseSetting()
        {
            InitializeComponent();
        }

        private DataTable _DataFilled = null;
        /// <summary>
        /// 填充数据
        /// </summary>
        public DataTable DataFilled
        {
            set
            {
                _DataFilled = value;
            }
            get
            {
                return _DataFilled;
            }
        }

        private int _currentSelectedID = -1;

        public int CurrentSelectedID
        {
            set { _currentSelectedID = value; }
            get { return _currentSelectedID; }
        }
        /// <summary>
        /// populate grid by module type
        /// </summary>
        public void PopulateGridData(IList<int> columnsWidth)
        {
            dataGridView1.DataSource = this.DataFilled;
            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            //set the width for each cols. 
            int i = 0;
            foreach (int currentCol in columnsWidth)
            {
                dataGridView1.Columns[i].Width = currentCol;
                i += 1;
            }
        }

        /// <summary>
        /// raise add event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            OnAddEvent();
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            OnUpdEvent();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            OnDelEvent();
        }

        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            //dg = dataGridView1;
            //OnRowSelectedEvent(dg, e);
        }

        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView temp = (DataGridView)sender;
            this.CurrentSelectedID = Int32.Parse(temp.Rows[e.RowIndex].Cells[0].FormattedValue.ToString());
        }

    }
}
